#include "ui/ColorSelectionPane.h"
#include "ui/ColorSelector.h"

#include <QScrollArea>
#include <QLabel>
ColorSelectionPane::ColorSelectionPane(QWidget *parent):QFrame(parent)
{
	m_parent = parent;
	m_layout = new QVBoxLayout();
	this->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
	this->setLayout(m_layout);
	m_layout->setSpacing(3);
	m_layout->setContentsMargins(0,0,0,0);
}

void ColorSelectionPane::addColorBlock(string name, QColor color)
{
	ColorSelector * c = new	 ColorSelector(name, color,this);
	m_layout->addWidget(c);
	c->setVisible(true);
	//m_layout->insertSpacing(10,10);
	//m_layout->update();
	this->repaint(contentsRect());
	QObject::connect(c, SIGNAL(colorChanged(string,QColor)), this, SLOT(colorChanged(string,QColor)));
	this->adjustSize();
	((QWidget*)this->parent())->adjustSize();
}
void ColorSelectionPane::removeAllBlocks()
{
	QObjectList cl = m_layout->children();
	printf("Removing\n");
	QLayoutItem *child;
	while ((child = m_layout->takeAt(0)) != 0) 
	{
		//child->widget()->hide();
		child->widget()->deleteLater();
	}
}

void ColorSelectionPane::colorChanged( string name, QColor color )
{
	emit colorBlockChanged(name, color);
}

